package client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by 10188 on 2018/3/6.
 */
public class NettyClient {


    public static String host = "127.0.0.1";
    public static int port = 5201;
    public static void main(String[] args) throws InterruptedException, IOException {

        EventLoopGroup group= new NioEventLoopGroup();
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new NettyClientInitializer());

        // 连接服务端
        Channel ch = b.connect(host, port).sync().channel();

        // 控制台输入
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        for (;;) {
            String line= in.readLine();
            if (line == null)
                continue;
            ch.writeAndFlush(line + "\r\n");
        }
    }
}
